﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZX.HIS.Common;

namespace ZX.HIS.UI.Controllers
{
    public class RegistInfoController : Controller
    {
        //
        // GET: /RegistInfo/

        /// <summary>
        /// 挂号信息显示添加修改页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 挂号信息分页查询方法
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public JsonResult FnRegistInfoPageList(int PageIndex, int PageSize)
        {
            string StrOrder = "";
            if (!String.IsNullOrEmpty(Request["StrOrder"]))
            {
                StrOrder = Request["StrOrder"];
            }
            ZX.HIS.Model.RegistInfo RIModel = new Model.RegistInfo();
            RIModel.HospitalId = 1001;
            if (!String.IsNullOrEmpty(Request["RegistChiName"]))
            {
                RIModel.RegistChiName = Request["RegistChiName"];
            }
            if (!String.IsNullOrEmpty(Request["UserNameOne"]))
            {
                RIModel.RegistChiName = Request["UserNameOne"];
            }
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            PageClass<ZX.HIS.Model.RegistInfo> PageList = RIBLL.RegistInfoPageList(PageIndex, PageSize, RIModel, StrOrder);
            return Json(PageList);
        }
        /// <summary>
        /// 获得一个实体类
        /// </summary>
        /// <param name="RegistId"></param>
        /// <returns></returns>
        public JsonResult FnGetRegistInfoModel(int RegistId)
        {
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            ZX.HIS.Model.RegistInfo RIModel = RIBLL.RegistInfoGetModel(RegistId);
            return Json(RIModel);
        }
        /// <summary>
        /// 所属部门的所有显示，用户表内的
        /// </summary>
        /// <param name="DepartId"></param>
        /// <returns></returns>
        public JsonResult FnGetUserList(int DepartId)
        {
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            return Json(RIBLL.GetUserList(HospitalId, DepartId));
        }
        /// <summary>
        /// 挂号信息添加
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistInfoAdd()
        {
            ZX.HIS.Model.UserInfo uModel = new ZX.HIS.Model.UserInfo();
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            uModel.HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
            //uModel.UserPwd = myCookie["UserName"];
            //uModel.ChineseName = HttpUtility.UrlDecode(myCookie["ChineseName"]);

            ZX.HIS.Model.RegistInfo RIModel = new Model.RegistInfo();
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            RIModel.UserIdTwo = 1001;
            RIModel.HospitalId = 0;
            if (Convert.ToInt32(uModel.HospitalId) != 0)
            {
                RIModel.HospitalId = Convert.ToInt32(uModel.HospitalId);
            }
            RIModel.RegistChiName = Request["RegistChiName"];
            RIModel.RegistSex = Convert.ToInt32(Request["RegistSex"]);
            RIModel.RegistAge = Convert.ToInt32(Request["RegistAge"]);
            RIModel.DepartId = Convert.ToInt32(Request["DepartId"]);
            RIModel.UserIdOne = Convert.ToInt32(Request["UserIdOne"]);
            RIModel.RegistTypeId = Convert.ToInt32(Request["RegistTypeId"]);
            RIModel.RegistNoPrice = Convert.ToDecimal(Request["RegistNoPrice"]);
            RIModel.RegistHasPrice = Convert.ToDecimal(Request["RegistHasPrice"]);
            RIModel.RegistRePrice = Convert.ToDecimal(Request["RegistRePrice"]);
            return Json(RIBLL.RegistInfoAdd(RIModel));
        }
        /// <summary>
        /// 挂号信息修改
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistInfoUpt()
        {
            ZX.HIS.Model.RegistInfo RIModel = new Model.RegistInfo();
            RIModel.RegistChiName = Request["RegistChiName"];
            RIModel.RegistId = Convert.ToInt32(Request["RegistId"]);
            RIModel.RegistSex = Convert.ToInt32(Request["RegistSex"]);
            RIModel.RegistAge = Convert.ToInt32(Request["RegistAge"]);
            RIModel.DepartId = Convert.ToInt32(Request["DepartId"]);
            RIModel.UserIdOne = Convert.ToInt32(Request["UserIdOne"]);
            RIModel.RegistTypeId = Convert.ToInt32(Request["RegistTypeId"]);
            RIModel.RegistNoPrice = Convert.ToDecimal(Request["RegistNoPrice"]);
            RIModel.RegistHasPrice = Convert.ToDecimal(Request["RegistHasPrice"]);
            RIModel.RegistRePrice = Convert.ToDecimal(Request["RegistRePrice"]);
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            return Json(RIBLL.RegistInfoUpt(RIModel));
        }
        /// <summary>
        /// Ajax调用返回当前用户下的未就诊患者返回第一个用户实体类
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistInfoTopRegistId()
        {
            int UserId = 0;
            int DepartId = 0;
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["UserId"]))
                {
                    UserId = Convert.ToInt32(myCookie["UserId"]);
                }
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    DepartId = Convert.ToInt32(myCookie["HospitalId"]);
                }
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            int RegistId = RIBLL.RegistInfoTopRegistId(DepartId, UserId, HospitalId);
            ZX.HIS.Model.RegistInfo RIModel = new Model.RegistInfo();
            if (RegistId == 0)
            {
                return Json(RIModel);
            }
            RIModel = RIBLL.RegistInfoGetModel(RegistId);
            int RegistState = 1;
            if (!RIBLL.RegistInfoUpt(RegistId, RegistState))
            {
                RIModel = null;
            }
            return Json(RIModel);
        }
        /// <summary>
        /// Ajax查询未就诊人数个数，返回int
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistInfoCount()
        {
            int UserId = 0;
            int DepartId = 0;
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["UserId"]))
                {
                    UserId = Convert.ToInt32(myCookie["UserId"]);
                }
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    DepartId = Convert.ToInt32(myCookie["HospitalId"]);
                }
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            return Json(RIBLL.RegistInfoCount(DepartId, UserId, HospitalId));
        }
        /// <summary>
        /// 挂号人的实体类
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistInfoList()
        {
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            ZX.HIS.BLL.RegistInfo RIBLL = new BLL.RegistInfo();
            return Json(RIBLL.RegistInfoList(HospitalId));
        }

    }
}
